from sklearn.tree import DecisionTreeClassifier
from sklearn.svm import SVC
from sklearn.neighbors import KNeighborsClassifier
from sklearn.ensemble import RandomForestClassifier, AdaBoostClassifier, GradientBoostingClassifier
from sklearn.naive_bayes import GaussianNB
import numpy as np
from sklearn.metrics import average_precision_score
import xgboost as xgb

class MultiClassifier(object):
    """description of class"""
    def __init__(self):
        self.models = [
            SVC(),
            DecisionTreeClassifier(),
            KNeighborsClassifier(),
            RandomForestClassifier(),
            GradientBoostingClassifier(),
            GaussianNB(),
            AdaBoostClassifier()
        ]

    def train(self,X,y):
        for model in self.models:
            model.fit(X,y)

    def predict(self,X):
        tmp = []
        result = []
        for model in self.models:
            tmp.append(model.predict(X))
        tmp = np.array(tmp)
        """
        for i in range(len(X)):
            if np.sum(tmp[:,i])>len(self.models)/2:
                result.append(1)
            else:
                result.append(0)
        return result
        """
        return tmp.T


    def score(self,X,y):
        p = self.predict(X)
        return average_precision_score(y, p)


class Ensemble(object):
    def __init__(self):
        self.m = xgb.XGBClassifier()

    def train(self, X,y):
        self.m.fit(X,y)

    def predict(self,X):
        return self.m.predict(X)

    def score(self,X,y):
        p = self.predict(X)
        return average_precision_score(y,p)